package com.sky.controller.admin;

import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理相关接口")
public class SetmealController {

    @Autowired
    SetmealService setmealService;

    /**
     * 添加套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加套餐")
    @CacheEvict(value = "category_setmeal",key = "#setmealDTO.categoryId")
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("添加套餐,套餐数据{}",setmealDTO);
        setmealService.insertSetmeal(setmealDTO);
        return Result.success();
    }
    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐")
    @CacheEvict(value = {"category_setmeal","setmeal_dish"},allEntries = true)
   // @CacheEvict(value = "setmeal_dish",key = "#setmealDTO.id")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐,套餐数据{}",setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
    /**
     * 套餐的 分页条件查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("套餐的 分页条件查询")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("套餐的 分页条件查询,条件分页数据:{}", setmealPageQueryDTO);

        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);

    }

    /**
     * 批量删除套餐
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    @CacheEvict(value = "category_setmeal",allEntries = true)
    public Result deleteByIds(@RequestParam("ids") List<Long> ids) {
        log.info("批量删除套餐,要删除的id有{}", ids);
        setmealService.deleteByIds(ids);
        return Result.success();

    }

    /**
     * 起售禁售套餐
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("起售禁售套餐")
    @CacheEvict(value = "category_setmeal",allEntries = true)
    public Result<String> startOrStop(@PathVariable("status") Integer status, Long id) {
        setmealService.startOrStop(status, id);
        return Result.success();
    }


    /**
     * 根据id查询套餐所有信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐所有信息")
    public Result<SetmealVO> selectById(@PathVariable Long id) {
        log.info("根据id查询套餐所有信息,id为{}", id);
        SetmealVO setmealVO = setmealService.selectById(id);
        return Result.success(setmealVO);

    }
}
